<template>
  <div class="container">
    <div class="containerEart">
      <p class="dialogTitle">重点场所风险评估</p>
      <div class="header">
        <div class="icon">
          <svg-icon class-name="error-icon" icon-class="error" style="margin-right:10px" v-if="showIcon" />
          <span>{{ titleOption }}</span>
        </div>
      </div>
    </div>
    <el-row :gutter="30">
      <el-col :span="21">
        <p style="margin: 10px 0;"><span
            @click="handleDownloadPort({ attachId: fileNoticeId, attachName: fileNoticeName })"
            style="cursor: pointer;color:#107ce5">{{
              fileNoticeName }}</span></p>
      </el-col>
      <el-col :span="3">
        <p style="color:#107ce5;margin: 10px 0;">
          <reportResult type="3"></reportResult>
        </p>
      </el-col>
    </el-row>

    <div class="tabsBox">
      <el-row :gutter="10" class="button" v-if="!isEnd">
       <el-col :span="1.5" v-if="activeName == 'first'">
        <el-button type="primary" @click="handlePic">
          <el-icon>
            <Picture />
          </el-icon><span style="margin-left:10px">一键出图</span>
        </el-button>
      </el-col>
      <el-col :span="1.5" v-if="activeName == 'first'">
        <el-button type="primary" @click="openUpload">
          <svg-icon class-name="upload-icon" icon-class="upload" /><span style="margin-left:10px">成果上传</span>
        </el-button>
      </el-col>
      <!-- <el-col :span="1.5">
                <el-button type="primary" @click="handleDownload">
                    <svg-icon class-name="download-icon" icon-class="download" /><span
                        style="margin-left:10px">批量下载</span>
                </el-button>
            </el-col> -->
      <!-- <el-col :span="1.5" v-if="activeName == 'second'">
        <el-button type="primary" @click="handleSubmit" :disabled="multiple">
          <svg-icon class-name="submit-icon" icon-class="submit" /><span style="margin-left:10px">提交</span>
        </el-button>
      </el-col> -->
    </el-row>
      <el-tabs v-model="activeName" type="card" class="tab" @tab-click="handleClick">
      <el-tab-pane label="中间成果" name="first">
        <el-table v-loading="loading" :data="dataList" stripe @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="55" align="center" />
          <el-table-column label="标题" align="center" prop="title" />
          <el-table-column label="评估内容" align="center" prop="krContent" />
          <el-table-column label="生成时间" align="center" prop="krDate" />
          <el-table-column label="业务人员" align="center" prop="krPeople" />
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
            <template #default="scope">
              <el-button type="text" @click="handleDetil(scope.row)">查看</el-button>
              <el-button type="text" @click="handleEndResult(scope.row)" v-if="!isEnd">提交</el-button>
              <el-button type="text" @click="handledel(scope.row)" v-if="!isEnd">删除</el-button>
              <el-button type="text" @click="handleDownload(scope.row)">下载</el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-tab-pane>
      <el-tab-pane label="最终成果" name="second" class="two">
        <el-table v-loading="loading" :data="dataLists" border @selection-change="handleSelectionChange"
          :span-method="objectSpanMethod">
          <el-table-column type="selection" width="55" align="center" prop="krContent" />
          <el-table-column label="评估内容" align="center" prop="krContent" />
          <el-table-column label="标题" align="center" prop="title" />
          <el-table-column label="生成时间" align="center" prop="krDate" />
          <!-- <el-table-column label="提交时间" align="center" prop="submitTime">
            <template #default="scope">
              <span v-if="scope.row.status == '2'">{{ scope.row.submitTime }}</span>
              <span v-else></span>
            </template>
          </el-table-column> -->
          <el-table-column label="业务人员" align="center" prop="krPeople" />
          <!-- <el-table-column label="提交状态" align="center" prop="status">
            <template #default="scope">
              <span v-if="scope.row.status == '2'">已提交</span>
              <span v-else>未提交</span>
            </template>
          </el-table-column> -->
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
            <template #default="scope">
              <el-button type="text" @click="handleDetil(scope.row)">查看</el-button>
              <el-button type="text" @click="handleRemove(scope.row)" v-if="!isEnd">移除</el-button>
              <el-button type="text" @click="handleDownload(scope.row)">下载</el-button>
            </template>
          </el-table-column>
          <!-- <el-table-column label="描述" align="center" prop="krContent">
            <template #default="scope">
              <el-button type="text" @click="addOpenDescribe(scope.row)">编辑描述</el-button>
            </template>
          </el-table-column> -->
        </el-table>
      </el-tab-pane>
    </el-tabs>
    </div>

    <div>
      <p style="font-size: 16px;font-weight: bold;">地震危险性评估功能说明</p>
      <ul class="ulList">
        <li>【一键出图】：根据避难场所分布情况以及可容纳避难人数情况，给出避难疏散路径规划。</li>
        <li>【成果上传】：从本地上传成果至系统中。</li>
        <li>&lt;中间成果&gt;存放通过计算或本地上传的所有成果。</li>
        <li>&lt;最终成果&gt;存放最终放入报告中的成果，报告以&lt;最终成果&gt;的内容为准进行生成。</li>
        <li>所有评估完成后，需返回评估任务界面通过【报告管理】进行报告生成、上传提交等操作。</li>
      </ul>
    </div>

    <!-- 编辑描述 -->
    <el-dialog v-model="openDescribe" width="800px" title="编辑描述">
      <p style="margin-top:20px"></p>
      <el-button type="primary" @click="addDescribe" v-if="describe.length < 4" style="margin-bottom:10px">
        <svg-icon class-name="upload-icon" icon-class="upload" /><span style="margin-left:10px">添加描述</span>
      </el-button>
      <el-form ref="describeRef" :model="describe" :rules="rules" label-width="150px" v-if="describe.length > 0">
        <el-row>
          <template v-for="(item, index) in describe" :key="index">
            <el-col :span="22">
              <el-form-item label="描述" :prop="index + '.describe'" :rules="rules.describe">
                <el-input v-model="item.describe" type="textarea" maxlength="500" show-word-limit
                  :autosize="{ minRows: 5, maxRows: 5 }" placeholder="请输入描述" />
              </el-form-item>
            </el-col>
            <el-col :span="2">
              <el-icon color="red" :size="25" style="margin:20px" @click="remove(index)">
                <Remove />
              </el-icon>
            </el-col>
          </template>
        </el-row>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="handleDescribe">确定</el-button>
          <el-button @click="openDescribe = false">取消</el-button>
        </div>
      </template>
    </el-dialog>

    <!-- 成果上传对话框 -->
    <el-dialog v-model="open" width="800px" :title="title" append-to-body>
      <p></p>
      <el-form ref="emUploadRef" :model="queryParams" :rules="rules" label-width="150px">
        <el-form-item label="评估内容" prop="krContent">
          <el-radio-group v-model="queryParams.krContent" :disabled="title=='查看'">
            <el-radio label="重点场所风险评估">重点场所风险评估</el-radio>
            <el-radio label="地震应急疏散辅助决策图">地震应急疏散辅助决策图</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="重点目标" prop="zdmbId" v-if="queryParams.krContent=='地震应急疏散辅助决策图'&& title!='查看'">
            <el-select v-model="queryParams.zdmbId" placeholder="请选择重点目标" clearable :disabled="activeName == 'second'">
                <el-option v-for="item in option" :key="item.ssId" :label="item.ssJzwmc" :value="item.ssId">
                </el-option>
            </el-select>
        </el-form-item>
        <el-form-item label="标题" prop="title">
          <el-input v-model="queryParams.title" placeholder="请输入标题" :disabled="activeName == 'second'" />
        </el-form-item>
        <el-form-item label="上传图片" prop="pictureId">
          <template v-if="queryParams.dataMessage=='成果上传'">
            <image-upload ref="imageUpload" v-model="queryParams.attach" :limit="limit"
                          :disabled="activeName == 'second'" />
          </template>
          <template v-if="queryParams.dataMessage=='一键出图'">
            <imgUploads ref="imageUpload" :limit="limit" v-model="queryParams.attach" />
          </template>
        </el-form-item>
        <el-form-item label="数据信息" v-if="title == '查看'">
          {{ queryParams.dataMessage }}
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="handleUpload" v-if="activeName == 'first'">确定</el-button>
          <el-button @click="cancelUpload">取消</el-button>
        </div>
      </template>
    </el-dialog>

    <!-- 一键出图 -->
    <el-dialog title="一键出图（地震应急疏散辅助决策图）" v-if="openPic" v-model="openPic" width="800px" append-to-body :close-on-click-modal="false">
      <el-form ref="picRef" label-width="140px" :model="form" :rules="rules">
        <el-row style="margin: 20px 0;">
          <el-col :span="12">
            <el-form-item label="制图单位" prop="ztdw">
              <el-input v-model="form.ztdw" placeholder="请输入制图单位" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="出图范围(km)" prop="ctfw">
              <el-input type="number" v-model="form.ctfw" placeholder="请输入出图范围" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="重点目标" prop="zdmb">
              <el-select v-model="form.zdmb" placeholder="请选择重点目标" clearable style="width:100%">
                <el-option v-for="item in option" :key="item.ssId" :label="item.ssJzwmc" :value="item.ssJzwmc">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="图件模板" prop="tjmb" label-width="120px">
              <el-select v-model="form.tjmb" placeholder="请选择" style="width: 100%">
                <el-option v-for="item in typeNameOption" :key="item.id" :label="item.name"
                           :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="图件标题" prop="tjbt">
              <el-input v-model="form.tjbt" placeholder="请输入图件标题" clearable />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row style="margin: 20px 0;">
          <el-col :span="12">
            <el-form-item label="城镇住宅" prop="czzz">
              <SelectVersion v-model="form.selectDataVersion.czzz.dataVersion"
                             name="czzz" title="城镇住宅数据" :num="form.selectDataVersion.czzz.num"
                             @getSelectVersion="getSelectVersion" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="农村非住宅" prop="ncfzz">
              <SelectVersion v-model="form.selectDataVersion.ncfzz.dataVersion"
                             name="ncfzz" title="农村非住宅数据" :num="form.selectDataVersion.ncfzz.num"
                             @getSelectVersion="getSelectVersion" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row style="margin: 20px 0;">
          <el-col :span="12">
            <el-form-item label="城镇非住宅" prop="czfzz">
              <SelectVersion v-model="form.selectDataVersion.czfzz.dataVersion"
                             name="czfzz" title="城镇非住宅数据" :num="form.selectDataVersion.czfzz.num"
                             @getSelectVersion="getSelectVersion" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="道路" prop="dl">
              <SelectVersion v-model="form.selectDataVersion.dl.dataVersion"
                             name="dl" title="道路数据" :num="form.selectDataVersion.dl.num"
                             @getSelectVersion="getSelectVersion" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row style="margin: 20px 0;">
          <el-col :span="12">
            <el-form-item label="农村住宅(独立住宅)" prop="nczzdlzz">
              <SelectVersion v-model="form.selectDataVersion.nczzdlzz.dataVersion"
                             name="nczzdlzz" title="农村住宅(独立住宅)数据" :num="form.selectDataVersion.nczzdlzz.num"
                             @getSelectVersion="getSelectVersion" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="铁路" prop="tl">
              <SelectVersion v-model="form.selectDataVersion.tl.dataVersion"
                             name="tl" title="铁路数据" :num="form.selectDataVersion.tl.num"
                             @getSelectVersion="getSelectVersion" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row style="margin: 20px 0;">
          <el-col :span="12">
            <el-form-item label="农村住宅(集合住宅)" prop="nczzjhzz">
              <SelectVersion v-model="form.selectDataVersion.nczzjhzz.dataVersion"
                             name="nczzjhzz" title="农村住宅(集合住宅)数据" :num="form.selectDataVersion.nczzjhzz.num"
                             @getSelectVersion="getSelectVersion" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="应急避难场所" prop="selectDataVersion.yjbncs.dataVersion" :rules="rules.yjbncs">
              <SelectVersion v-model="form.selectDataVersion.yjbncs.dataVersion"
                             name="yjbncs" title="应急避难场所数据" :num="form.selectDataVersion.yjbncs.num"
                             @getSelectVersion="getSelectVersion" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row style="margin: 20px 0;">
          <el-col :span="12">
            <el-form-item label="道路网络数据集" prop="selectDataVersion.network.dataVersion" :rules="rules.network">
              <!--<div style="margin:0 auto">
                <span style="color: #107ce1;cursor: pointer;" v-if="form.selectDataVersion.network" @click="handleSelect()">{{ form.selectDataVersion.network }}</span>
                <el-button @click="handleSelect()" v-else>选择</el-button>
              </div>-->
              <SelectVersion v-model="form.selectDataVersion.network.dataVersion"
                             name="network" title="道路网络数据集" :num="form.selectDataVersion.network.num"
                             @getSelectVersion="getSelectVersion" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="基础地理数据" prop="jcdlsj">
              <div style="margin:0 auto">
                <span style="color: #107ce1;cursor: pointer;" v-if="form.selectDataVersion.jcdlsj.dataVersion" @click="openUploadDialog=true">{{ form.selectDataVersion.jcdlsj.dataVersion }}</span>
                <el-button @click="openUploadDialog=true" v-else>上传</el-button>
              </div>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="plot">一键出图</el-button>
          <el-button @click="openPic = false">取 消</el-button>
        </div>
      </template>
    </el-dialog>

    <el-dialog title="地震应急疏散辅助决策图" v-if="openPic1" v-model="openPic1" width="600px" append-to-body :close-on-click-modal="false">
      <el-form ref="picRef1" :model="resultForm" :rules="rules" label-width="150px" style="margin: 20px 0;">
        <el-form-item label="标题" prop="title">
          <el-input v-model="resultForm.title" placeholder="请输入标题" />
        </el-form-item>
        <el-form-item label="图片" prop="attach">
          <imgUploads ref="imageUpload" :limit="limit" v-model="resultForm.attach" disabled />
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="saves">保 存</el-button>
          <el-button @click="openPic1 = false">取 消</el-button>
        </div>
      </template>
    </el-dialog>

    <!-- 商会对话框 -->
    <el-dialog v-model="showOption" width="400px" title="震情趋势" :close-on-click-modal="false" append-to-body>
      <p class="worrning">震情趋势已发生变化，请注意！</p>
      <el-radio v-model="radioOption" label="true" style="margin-left:10px">今日不再提醒</el-radio>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" :disabled="!radioOption" @click="ok">确定</el-button>
          <el-button @click="cancelOption">取消</el-button>
        </div>
      </template>
    </el-dialog>


    <!--上传工作空间-->
    <el-dialog title="上传" v-model="openUploadDialog" width="700px" top="200px" append-to-body :close-on-click-modal="false">
      <el-form ref="uploadRef" label-width="120px" :model="uploadForm" :rules="uploadRules">
        <el-form-item label="超图工作空间"  prop="attachIds" style="margin-top:20px;">
          <FileUpload :action="uploadFileUrl" :limit="2" ref="fileUpload" v-model="uploadForm.fileList" :fileSize="500" :fileType='["udbx", "smwu"]' />
        </el-form-item>
        <el-form-item label="">
          <el-link @click="handleDownloadHelp">
            <span style="color:red">（怎样获得工作空间文件？）</span>
          </el-link>
        </el-form-item>
        <el-form-item label="注意事项：">
          <el-row>
            1、仅支持超图桌面端软件生成的工作空间文件；
            <br/>
            2、请确保图例名称为中文；
          </el-row>
          <el-row>
            3、如有多个数据，请放在一个工作空间中保存并上传；
          </el-row>
          <el-row>
            4、坐标系要求：GCS_China_Geodetic_Coordinate_System_2000（EPSG:4490）
          </el-row>
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="fileSubmitForm">确 定</el-button>
          <el-button @click="openUploadDialog = false">取 消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>
<script setup name="emphasis">
import { getImport,getZdmb } from "@/api/business/activities"
import { listEmphasis, getEmphasis, uploadEmphasis, updateEmphasis, delEmphasis, listEmphasiss, firstSubmitDisasterAss,
  titleCheck, updataDescribe, removeDisasterAss, secondSubmitDisasterAss, assessEmphasisNetworkPath, getTypeNameByType } from "@/api/assess/emphasis.js";
import { newWorkspaceRestMap } from "@/api/security/networkdataset.js"
import { setcookieTimeFun, getCookieFun } from "@/utils/popout.js";
import { dataMethod } from '@/utils/spanTable.js'
import { isArray } from "@vue/shared";
import SelectVersion from "./SelectVersion/index.vue"
import reportResult from "@/components/reportResult/index.vue"
import FileUpload from "./FileUpload/index.vue"
import imgUploads from '@/components/ImageUploadnew/index.vue'

const { proxy } = getCurrentInstance();
const uploadFileUrl = ref(
    import.meta.env.VITE_APP_BASE_API + "/attachment/uploadSmwuFile1"
); // 上传的文件服务器地址
const route = useRoute();
const showIcon = ref(false);
const titleOption = ref();
const loading = ref(false);
const showOption = ref(false);
const open = ref(false);
const radioOption = ref(false);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const title = ref();
const id = ref();
const krRelation = ref();
const limit = ref(1);
const krId = ref();
const activeName = ref('first');
const spanObj = ref();
const openDescribe = ref(false);
const updateIds = ref([]);
const uploadIds = ref([]);
const oldTitle = ref();
const flagSubmit = ref(true);
const flagMessage = ref([]);
const isEnd = ref(true);
// 文件通知 信息
const fileNoticeName = ref();
const fileNoticeId = ref();
// 一键出图
const openPic = ref(false);
const option = ref([]);
const picSure = ref(true);
const openPic1 = ref(false);
const list = ref([]);
const typeNameOption = ref([]);//图件模板列表

const titleName = (rule, value, callback) => {
  if (!value) {
    callback(new Error('请输入标题'))
  } else if (value && oldTitle.value && title.value == '查看' && oldTitle.value == value) {
    callback()
  } else if (value) {
    const parmas = { iaId: route.query.id, title: value }
    titleCheck(parmas).then(res => {
      if (!res.data) {
        callback()
      } else {
        callback(new Error("该标题已存在，请重新输入"))
      }
    }).catch(_ => {
      callback(new Error(_.message))
    })
  }
}
const data = reactive({
  queryParams: {
    pictureId: '',
    attach: [],
    title: '',
    dataMessage: '成果上传',
    krContent: '重点场所风险评估',
  },
  dataList: [],
  dataLists: [],
  describe: [],
  form: {
    ztdw:null,//制图单位
    ctfw:null,//出图范围
    zdmb:null,//重点目标
    tjbt:null,//图件标题
    tjmb:null,//图件模板
    //一键出图版本选择
    selectDataVersion:{
      czzz: {num:"czzz",dataVersion:null},//城镇住宅
      ncfzz: {num:"ncfzz",dataVersion:null},//农村非住宅
      czfzz: {num:"czfzz",dataVersion:null},//城镇非住宅
      dl: {num:"dl1",dataVersion:null},//道路
      nczzdlzz: {num:"nczzdlzz",dataVersion:null},//农村住宅(独立住宅)
      tl: {num:"tlfbt",dataVersion:null},//铁路
      nczzjhzz: {num:"nczzjhzz",dataVersion:null},//农村住宅(集合住宅)
      yjbncs: {num:"csbncsm",dataVersion:null},//应急避难场所
      network: {num:"network",dataVersion:null},//道路网络数据集
      jcdlsj: {num:"jcdlsj",dataVersion:null},//基础地理数据
    },
  },
  rules: {
    pictureId: [{ required: true, message: "图片不能为空", trigger: "blur" }],
    // zdmb : [{ required: true, message: "重点目标不能为空", trigger: "blur" }],
    title: [{ required: true, validator: titleName, trigger: "blur" }],
    describe: [{ required: true, message: "描述不能为空", trigger: "blur" }],

    ztdw: [{ required: true, message: "制图单位不能为空", trigger: "blur" }],
    ctfw: [{ required: true, message: "出图范围不能为空", trigger: "blur" }],
    zdmb: [{ required: true, message: "重点目标不能为空", trigger: "change" }],
    zdmbId: [{ required: true, message: "重点目标不能为空", trigger: "change" }],
    // xzmb: [{ required: true, message: "图件模板不能为空", trigger: "change" }],
    tjmb: [{ required: true, message: "图件模板不能为空", trigger: "change" }],
    tjbt: [{ required: true, message: "图件标题不能为空", trigger: "blur" }],
    // dataVersion: [{ required: false, message: "图件标题不能为空", trigger: "blur" }],
    yjbncs: [{ required: true, message: "应急避难场所必须选择1个版本", trigger: "change" }],
    network: [{ required: true, message: "道路网络数据集必须选择1个版本", trigger: "change" }],
  },
  uploadForm:{
    fileList:[],
    attachIds:'',
  },
  uploadRules: {
    attachIds: [{ required: true, message: "应上传1个.smwu文件和1个.udbx文件", trigger: "blur" }],
  },
  resultForm:{
    title:"",
    attach:[],
  }
})
const { queryParams, dataList, dataLists, describe, rules, form, uploadForm, uploadRules, resultForm } = toRefs(data)
const handleClick = (tab, event) => {
  if (tab.props.name == "first") {
    getList();
  } else {
    getLists();
  }
}
/** 多选框选中数据 */
function handleSelectionChange(selection) {
  ids.value = selection.map((item) => item.krId);
  flagMessage.value = [];
  flagSubmit.value = true;
  if (activeName.value == 'second') {
    selection.forEach((item) => {
      if (!item.descriptions) {
        flagSubmit.value = false;
        flagMessage.value.push(item.krContent)
      }
    })
    uploadIds.value = [];
    dataLists.value.forEach(item => {
      uploadIds.value.push(item.krId)
    })
  }
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}

// 合并列
function objectSpanMethod({ row, column, rowIndex, columnIndex }) {
  //判断合并列
  const _row = spanObj.value[column.property] ? spanObj.value[column.property][rowIndex] : 1;
  const _col = _row > 0 ? 1 : 0;
  return {
    rowspan: _row,
    colspan: _col,
  }
}

/** 获取列表操作 */
function getList() {
  krRelation.value = route.query.id
  id.value = route.query.id;
  loading.value = true;
  listEmphasis(id.value).then((response) => {
    dataList.value = response.data ? response.data : [];;
    loading.value = false;
  });
}

function getLists() {
  krRelation.value = route.query.id
  id.value = route.query.id;
  loading.value = true;
  listEmphasiss(id.value).then((response) => {
    dataLists.value = response.data ? response.data : [];;
    spanObj.value = dataMethod(dataLists.value, ['krContent']);
    loading.value = false;
  });
}
// 打开成果上传开关
function openUpload() {
  reset();
  title.value = "上传"
  open.value = true;
}

// 重置上传
function reset() {
  queryParams.value = {
    pictureId: '',
    attach: [],
    title: '',
    dataMessage: '成果上传',
    krContent: '重点场所风险评估',
  }
  proxy.resetForm("emUploadRef");
}

// 成果上传
function handleUpload() {
  const fileList = JSON.parse(JSON.stringify(proxy.$refs["imageUpload"].fileList));
  const attachIds = [];
  for (var i = 0; i < fileList.length; i++) {
    attachIds.push(fileList[i].attachId)
  }
  queryParams.value.pictureId = attachIds.join(",");
  proxy.$refs["emUploadRef"].validate(valid => {
    if (valid) {
      if (title.value == '上传') {
        upload();
      } else if (title.value == '查看') {
        updateEmphasis({ ...queryParams.value, krRelation: route.query.id }).then(response => {
          proxy.$modal.msgSuccess("保存成功");
          open.value = false;
          getList();
        });
      }
    }
  });
}
function upload() {
  uploadEmphasis({ ...queryParams.value, krRelation: route.query.id }).then(response => {
    proxy.$modal.msgSuccess("上传成功");
    open.value = false;
    getList();
  }).catch(() => { });
}

function getDetail(id) {
  getEmphasis(id).then(response => {
    queryParams.value = response.data.keyplaceRiskassessment;
    queryParams.value.attach = response.data.attach ? [response.data.attach] : [];
    title.value = "查看"
    open.value = true;
  })
}

/** 查看方法*/
function handleDetil(row) {
  title.value = '查看';
  reset();
  getDetail(row.krId)
}

// 取消成果上传
function cancelUpload() {
  open.value = false;
}

/** 删除按钮操作 */
function handledel(row) {
  const id = row.krId;
  proxy.$modal.confirm('是否确认删除' + row.krContent + '的数据项？').then(function () {
    return delEmphasis(id);
  }).then(() => {
    getList();
    proxy.$modal.msgSuccess("删除成功");
  }).catch(() => { });
}

// 提交最终成果
function handleEndResult(row) {
  firstSubmitDisasterAss(row.krId).then(res => {
    getList();
    proxy.$modal.msgSuccess("提交成功");
  })
}
// 移除
function handleRemove(row) {
  removeDisasterAss(row.krId).then(res => {
    getLists();
    proxy.$modal.msgSuccess("移除成功");
  })
}

// 编辑描述
function addOpenDescribe(row) {
  describe.value = [];
  getEmphasis(row.krId).then(response => {
    if (isArray(response.data.keyplaceRiskassessment.descriptions)) {
      response.data.keyplaceRiskassessment.descriptions.forEach(item => {
        describe.value.push({ describe: item })
      });
    } else {
      describe.value = [];
    }

    openDescribe.value = true;
    proxy.resetForm("describeRef");
  })
  updateIds.value = [];
  dataLists.value.forEach(item => {
    if (item.krContent == row.krContent) {
      updateIds.value.push(item.krId)
    }
  })
}
// 删除描述
function remove(index) {
  describe.value.splice(index, 1)
}
// 添加
function addDescribe() {
  describe.value.push({ describe: '' });
}
function handleDescribe() {
  if (describe.value.length == 0) {
    const query = { ids: updateIds.value, descriptions: null };
    updataDescribe(query).then(res => {
      getLists();
      openDescribe.value = false;
      proxy.$modal.msgSuccess("编辑成功");
    })
  } else {
    proxy.$refs["describeRef"].validate(valid => {
      if (valid) {
        describe.value = describe.value.map(item => {
          return item.describe
        })
        const query = { ids: updateIds.value, descriptions: describe.value };
        updataDescribe(query).then(res => {
          getLists();
          openDescribe.value = false;
          proxy.$modal.msgSuccess("编辑成功");
        })
      }
    });
  }
}
// 评估
function handleAssess() {

}
// 下载
function handleDownload(row) {
  if (row.dataMessage == '成果上传') {
        location.href = import.meta.env.VITE_APP_BASE_API + "/attachment/downLoadFile?attachId=" + encodeURIComponent(row.pictureId);
    } else {
        location.href = import.meta.env.VITE_APP_BASE_API + "/attachment/downLoad?attachId=" + encodeURIComponent(row.pictureId);
    }
}

// 下载文件
function handleDownloadPort(row) {
  var query = {
    attachId: row.attachId,
    name: row.attachName
  }
  location.href = import.meta.env.VITE_APP_BASE_API + "/attachment/downLoadFile?attachId=" + encodeURIComponent(query.attachId);
};

// 出图部分
function handlePic() {
  openPic.value = true;
  proxy.resetForm("picRef");
}
//获取选择的版本
function getSelectVersion(obj) {
  form.value.selectDataVersion[obj.name].dataVersion = obj.code;
  form.value.selectDataVersion[obj.name].num = obj.num;
  console.log(form.value.selectDataVersion);
}
// 一键出图
function plot() {
  proxy.$refs["picRef"].validate(valid => {
    if (valid) {
      proxy.$modal.loading("正在出图，请稍候...");
      assessEmphasisNetworkPath({...form.value,...form.value.selectDataVersion}).then(res => {
        proxy.$modal.closeLoading();
        if(res.code == 200){
          let attach = res.data.attach;
          if(attach){
            openPic1.value = true;
            proxy.resetForm("picRef1");
            resultForm.value.title = res.data.title;
            resultForm.value.attach = [attach];
            proxy.$modal.alertSuccess("出图成功");
          }
        }
      }).catch(() => {
        proxy.$modal.closeLoading();
        proxy.$modal.alertError("出图失败");
      });
    }
  });
}

// 上传一键出图
function saves() {
  proxy.$refs["picRef1"].validate(valid => {
    if (valid) {
      let params = {
        dataMessage:"一键出图",
        krContent:"地震应急疏散辅助决策图",
        pictureId:resultForm.value.attach[0].attachId,
        title:resultForm.value.title,
        krRelation: route.query.id
      };
      uploadEmphasis(params).then(response => {
        proxy.$modal.msgSuccess("上传成功");
        openPic.value = false;
        openPic1.value = false;
        getList();
      }).catch(() => { });
    }
  });
}

// 提交
function handleSubmit() {
  if (!flagSubmit.value) {
    proxy.$modal.confirm(flagMessage.value.join(',') + '的描述未添加,是否提交').then(function () {
      return secondSubmitDisasterAss(uploadIds.value);
    }).then(() => {
      getLists();
      proxy.$modal.msgSuccess("提交成功");
    }).catch(() => { });
  } else {
    secondSubmitDisasterAss(uploadIds.value).then(res => {
      getLists();
      proxy.$modal.msgSuccess("提交成功");
    })
  }
}

// 监听单选按钮
watch(showIcon, (val) => {
  showOption.value = val;
  if (showOption.value) {
    getTimeSetCookieFun(`emphasisCookie${route.query.id}`)
  }
})

// 获取日期时间
function getTimeSetCookieFun(name) {
  var day = getCookieFun(name) == '' ? '' : getCookieFun(name);
  if (day == '') {
    // console.log('没有cookie,说明过期或者还没有存')
    showOption.value = true;
  } else {
    var newTime = new Date().getDate();
    if (newTime > day) {
      // console.log('我是新的一天,我要弹窗')
      showOption.value = true;
    } else {
      showOption.value = false;
    }
  }
}
// 取消商会意见
function cancelOption() {
  showOption.value = false;
}
// 确认不再提示
function ok() {
  var newTime = new Date().getDate();
  setcookieTimeFun(`emphasisCookie${route.query.id}`, newTime, 1)
  showOption.value = false;
}
function getOpinion() {
  getImport(route.query.id).then(res => {
    titleOption.value = res.data.importantActivity.iaOpinion;
    option.value = [];
    const query = { province: res.data.importantActivity.provinceId, city: res.data.importantActivity.cityId, county: res.data.importantActivity.countiesId }
        getZdmb(query).then(res => {
          option.value = res.data;
        })
    showIcon.value = Boolean(Number(res.data.importantActivity.iaOpinionStatus));
    fileNoticeName.value = res.data.list[0].attachName;
    fileNoticeId.value = res.data.list[0].attachId;
    isEnd.value = res.data.importantActivity.iaActivityStatus==1;
  })
}

const openUploadDialog = ref(false);
//基础地理数据超图工作空间上传
function fileSubmitForm(){
  const fileList = JSON.parse(
      JSON.stringify(proxy.$refs["fileUpload"].fileList)
  );
  console.log(fileList);
  let smwuCount = 0;
  let udbxCount = 0;
  let attachIdsArr = [];
  for (let i = 0; i < fileList.length; i++) {
    attachIdsArr.push(fileList[i].attachId);
    if(fileList[i].name.endsWith(".smwu")){
      smwuCount++;
    }else if(fileList[i].name.endsWith(".udbx")){
      udbxCount++;
    }
  }
  if(smwuCount==1 && udbxCount==1 && fileList.length==2){
    //成功上传1个.smwu文件和1个.udbx文件
    uploadForm.value.attachIds = attachIdsArr.join(",");
  }else{//清空
    uploadForm.value.attachIds = "";
  }
  proxy.$refs["uploadRef"].validate(valid => {
    if (valid) {
      proxy.$modal.confirm('是否确认上传超图工作空间并发布地图服务？').then(function () {
        proxy.$modal.loading("正在发布，请稍候!");
        newWorkspaceRestMap(uploadForm.value).then(res => {
          proxy.$modal.closeLoading();
          if(res.code == 200){
            form.value.selectDataVersion.jcdlsj.dataVersion = res.data;
            proxy.$modal.alertSuccess("发布成功");
            uploadForm.value.fileList = [];
            openUploadDialog.value = false;
          }else{
            form.value.selectDataVersion.jcdlsj.dataVersion = null;
            proxy.$modal.alertSuccess("发布失败");
          }
        }).catch(() => {
          form.value.selectDataVersion.jcdlsj.dataVersion = null;
          proxy.$modal.closeLoading();
          proxy.$modal.alertError("发布失败");
        });
      });
    }
  });
}

//下载帮助文档
function handleDownloadHelp(){
  importTemplate("基础地理信息数据上传教程.pdf");
}

// 模板下载
function importTemplate(name) {
  proxy.download("/fxfzaqbz/data/downloadExcel", {
    fileName: name
  }, name);
}

//查询图件模板列表
function getTypeName() {
  let type = 11;//地震应急疏散辅助决策图
  getTypeNameByType(type).then(res => {
    typeNameOption.value = res.data || []
  })
}

getOpinion();
getList();
getTypeName();
</script>
<style lang="scss" scoped>
.container {
  margin: 0px auto;
  height: 100%;
  width: 1200px;
  overflow-x: hidden;
  overflow-y: auto;
  position: relative;

  .worrning {
    width: 340px;
    height: 110px;
    color: #3d4a5d;
    font-size: 18px;
    line-height: 26px;
    background: #f5f9fe;
    margin: 30px auto 10px;
    padding: 15px;
  }

  .header {
    padding: 10px 0px;

    .title {
      font-size: 18px;
      font-weight: bold;
    }

    div {
      height: 60px;
      line-height: 60px;
      margin-top: 10px;

      &.icon {
        padding: 0 20px;
        background: #f5f9fe;
      }
    }
  }

  .tabsBox {
    padding: 0;
    margin: 0;
    position: relative;
  }

  .button {
    position: absolute;
    top: 5px;
    left: 205px;
    z-index: 200;
  }

  .two {
    :deep(.el-table) td.el-table__cell {
      border-bottom: 1px solid #ebeef5 !important;
      border-right: 1px solid #ebeef5 !important;
    }
  }
}

.ulList {
  li {
    line-height: 30px;
  }

  li::marker {
    color: #F56C6C;
    font-size: 25px;
  }
}

:deep(.el-link){
  --el-link-hover-text-color:red;
}
</style>
  